<template>
	<view class="login-container">
		<nav-bar isWhite :bgColor="['#3350D9','#1152FC']" fontColor="#FFF" title="登录"></nav-bar>
		<view class="identify-icon">
			<image src="../../static/icon/weixiu.png"></image>
		</view>
		<view class="login">
			<view class="login-item">
				<view class="login-input">
					<view class="icon1">
						<image src="../../static/icon/zhanghao.png"></image>
					</view>
					<input type="text" v-model="params.accountName" placeholder="请输入账号" />
				</view>
			</view>
			<view class="login-item">
				<view class="login-input">
					<view class="icon1">
						<image src="../../static/icon/suo.png"></image>
					</view>
					<input class="forget" :password="isPassword" type="text" v-model="params.password" placeholder="请输入密码" />
					<view class="change-icon" v-if="isPassword" @click="changeStatus">
						<image src="../../static/icon/open.png"></image>
					</view>
					<view class="change-icon" v-else @click="changeStatus">
						<image src="../../static/icon/close.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="forget-password" @click="goForgetPassword">忘记密码</view> -->
		<button class="login-btn" @click="login">登录</button>
		<view class="argee">
			<radio color="#1152FC" value="agreementSelected" :checked="agreementChecked" @click="radioClick"></radio>
			我已阅读并同意<text @click="goAgreement">《用户协议》</text>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				params: {
					groupId: uni.getStorageSync('groupId'),
					accountName: '',
					password: '',
					authkey: null,
					authType: 3
				},
				verifyShow: true,
				verifyTip: 59,
				isPassword: true,
				agreementChecked: false
			}
		},
		methods: {
			radioClick() {
				this.agreementChecked = !this.agreementChecked;
			},
			changeStatus() {
				if (this.isPassword == false) {
					this.isPassword = true
					// this.inputType = 'text'
				} else {
					this.isPassword = false
					// this.inputType = 'password'
				}
			},
			// 跳转主页
			goIndex() {
				uni.switchTab({
					url: '../index/index'
				})
			},
			// 登录
			login() {
				// uni.requestSubscribeMessage({
				// 	tmplIds: ['iQNLTsg16IVNJrt1EOUYjKdpODoiocEHK-Q7vNztrko'],
				// 	success(res) {
				// 		console.log(res)
				// 	}
				// })
				console.log(this.agreementChecked)
				if (this.params.accountName.trim() == '') {
					uni.showToast({
						title: '请输入账号',
						icon: 'none'
					})
				} else if (this.params.password.trim() == '') {
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					})
				} else if(this.agreementChecked === false){
					uni.showToast({
						title: '请勾选同意下方的用户协议',
						icon: 'none'
					})
				}else {
					// console.log('消息')
					this.goLogin()
				}
			},
			goForgetPassword() {
				uni.navigateTo({
					url: '../forgetPassword/forgetPassword'
				})
			},
			goLogin() {
				uni.showLoading({
					title: '登录中'
				});
				this.params.authkey = parseInt(uni.getStorageSync('authKey'))
				this.$http2.post('auth/ticketOperator/verifyPassword', this.params).then(res => {
					console.log(res)
					if (res.code === 10000) {
						console.log(res)
						uni.switchTab({
							url: '../index/index',
						})
						uni.setStorageSync('login', true)
					} else {
						uni.showToast({
							title: '用户名或者密码错误',
							icon: 'none'
						})
					}
				})
			},
			goAgreement() {
				uni.navigateTo({
					url: '../userAgreement/userAgreement'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {}

	.login-container {
		width: 100vw;
		height: 100vh;
		background: url();
		background-size: 100% 100%;

		.identify-icon {
			width: 200rpx;
			height: 200rpx;
			position: absolute;
			left: 50%;
			top: 100rpx;
			transform: translate(-50%);

			image {
				width: 100%;
				height: 100%;
			}
		}

		.login {
			position: absolute;
			width: 651rpx;
			height: 240rpx;
			left: 51rpx;
			top: 340rpx;

			.login-item {
				width: 651rpx;
				height: 50%;
				border-bottom: 1rpx solid #E5E5E5;
				display: flex;
				align-items: center;

				.login-input {
					position: relative;
					width: 100%;
					height: 80%;
					z-index: 99;
					display: flex;
					font-size: 28rpx;
					align-items: center;

					.code {
						color: #7DAFFF;
						font-size: 24rpx;
					}

					.verify {
						width: 200rpx;
						color: #7DAFFF;
						font-size: 24rpx;
					}

					input {
						width: 590rpx;
					}

					.code-input {
						width: 454rpx;
					}

					.change-icon {
						width: 39rpx;
						height: 21rpx;
						top: 32rpx;
						right: 14rpx;
						position: absolute;

						image {
							width: 100%;
							height: 100%;
						}
					}

					.forget {
						width: 458rpx;
					}
				}
			}
		}

		.icon1 {
			width: 32rpx;
			height: 38rpx;
			margin-right: 29rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.icon2 {
			width: 34rpx;
			height: 38rpx;
			margin-right: 29rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.login-btn {
			width: 560rpx;
			height: 82rpx;
			border-radius: 41rpx;
			color: #fff;
			font-size: 32rpx;
			text-align: center;
			line-height: 82rpx;
			position: absolute;
			left: 95rpx;
			top: 678rpx;
			background: linear-gradient(0deg, #3AA9FE, #5A9AFF);
		}

		.forget-password {
			position: absolute;
			top: 600rpx;
			left: 591rpx;
			font-size: 28rpx;
			color: #666;
		}

		.argee {
			position: absolute;
			left: 190rpx;
			top: 790rpx;
			color: #BBBBBB;
			font-size: 28rpx;
			radio {
				position: relative;
				top: -4rpx;
				transform:scale(0.9)
			}
			text {
				color: #7DAFFF;
			}
		}
	}
</style>
